﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace OpenLS.Spreadsheet.UI.Internals
{
    class FirstNonNullConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return Enumerable.FirstOrDefault(values, v => v != null && v != DependencyProperty.UnsetValue);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
        public static IMultiValueConverter Instance { get { return new FirstNonNullConverter(); } }
    }
}
